const tokenName = `${APP_TYPE}_book-web`;

export function getAuthority(str?: string) {
  const authorityString: any =
    typeof str === 'undefined' ? (localStorage.getItem(tokenName) || '{}') : str;
  let authority;
  try {
    authority = JSON.parse(authorityString);
  } catch (e) {
    authority = authorityString;
  }
  if (typeof authority === 'string') {
    return [authority];
  }
  return authority;
}

export function setAuthority(authority: any) {
  const proAuthority = typeof authority === 'string' ? [authority] : authority;
  return localStorage.setItem(tokenName, JSON.stringify(proAuthority));
}

export function clearAuthority(authorityName?: string) {
  localStorage.removeItem(authorityName || tokenName)
}